<div class="row-fluid clearfix">
    <div class="col-md-12 column">
        <ul class="breadcrumb">
            <li>
                <a href="index.html">首页</a>
            </li>
            <li class="active">
                用户费率设置
            </li>
        </ul>
    </div>
    <div class="col-md-12 column">
        <div class="col-sm-12 div-page">
            <div class="col-sm-12 div-table">
                <div id="custom-toolbar">

                </div>
                <table id="table" class="table table-hover table-condensed" data-toolbar="#custom-toolbar"
                       data-click-to-select="true"  data-single-select="true" data-height="450">
                    <thead>
                    <tr>
                        <th data-field="state" data-checkbox="true"  ></th>
                        <th data-field="user_typeShow" data-halign="center" data-align="center">用户类型</th>
                        <th data-field="rate_tradefee" data-halign="center" data-align="center">折扣率</th>
                        <th data-field="sign_typeShow" data-halign="center" data-align="center">扣费类型</th>
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
        <div class="col-sm-12 alert alert-success div-alert " id="events-result" data-es="Aquí se muestra el resultado del evento"></div>
        <!-- #遮罩层 --->
        <div class="modal fade" id="modal-DataEdit" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <div class="modal-title" id="myModalLabel">
                            用户类型编辑
                        </div>
                    </div>
                    <form id="validForm" method="post" class="form-horizontal layer_msg">
                        <div class="modal-body">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">用户类型</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" data-field="user_typeShow" id="user_typeShow" name="user_typeShow" readonly />
                                    <input type="hidden" data-field="user_type" id="user_type" name="user_type" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">折扣率</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" data-field="rate_tradefee" id="rate_tradefee" name="rate_tradefee" placeholder="折扣率"
                                           pattern="^[0-1]$|0\.[0-9]$|0\.[0-9][0-9]$|1\.[0][0]$|1\.[0]$" data-fv-regexp-message="折扣率应在0和1之间，最多2位小数"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">扣费类型</label>
                                <div class="col-sm-9">
                                    <input type="hidden" class="form-control" data-field="sign_typeShow" id="sign_typeShow" name="sign_typeShow" />
                                    <select class="form-control" data-fv-notempty data-fv-notempty-message="扣费类型" data-field="sign_type" id="sign_type" name="sign_type" onchange="">
                                        <option value="">请选择</option>
                                        <option value="1">转出方付费</option>
                                        <option value="0">转入方付费</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button id="modal-btn-save" type="submit" class="btn btn-primary">保存</button> <button id="modal-btn-close" type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>

    </div>
</div>

<script>
    $(function () {
        var btnHtml ;
        var btnRole = JSON.parse($.cookie("Role_note"));

        btnHtml = '<div class="form-inline" role="form">';
        btnHtml += (btnRole["CommonDataModify"]) ? '<button id="btn-CommonDataModify" type="button" role="button" class="btn btn-sm btn-Data btn-success disabled">' +
                '<span class="glyphicon glyphicon-pencil"></span> 修改</button> ' : '' ;

        $("#custom-toolbar").append(btnHtml);

        $('#table').bootstrapTable({
            url: globalUrl+'api/Expense?page=1&rows=99',
            responseHandler:function(resp){
                return resp.data.rows;
            },
            pagination:false,
            search:true
        })
                .on('click-row.bs.table', function (e, row, $element) {
                    //$("#events-result").text('Event: click-row.bs.table, data: ' + JSON.stringify(row));
                    /* by lichun 切换选中颜色*/
                    if ( $element.hasClass('selected') ) {
                        $element.removeClass('info');
                    }
                    else {
                        $element.parent('tbody').find(' > tr.selected ').removeClass("info");
                        $element.addClass('info');
                    }
                })
                .on('check.bs.table', function (e, row, $element) {
                    //$("#events-result").text('Event: check.bs.table, data: ' + JSON.stringify(row));
                    $(".btn-Data").removeClass("disabled").addClass("btn-success");
                })
                .on('uncheck.bs.table', function (e, row, $element) {
                    //$("#events-result").text('Event: uncheck.bs.table, data: ' + JSON.stringify(row));
                    $(".btn-Data").removeClass("btn-success").addClass("disabled");
                });

        ///初始化下拉列表
        //FormatSelect("../json/dropdownlist.txt",$(".dropdown"),"-1");
        ///下拉列表绑定变更事件
        $('#sign_type').change(function(){
            refreshSelectShow($("#sign_type"),$("#sign_typeShow"));
        });

        ///弹出层验证，submit时生效
        $('#validForm')
                .formValidation()
                .on('success.form.fv', function(e) {

                    // Prevent form submission
                    e.preventDefault();

                    // Get the form instance
                    var $form = $(e.target);

                    // Get the FormValidation instance
                    var bv = $form.data('formValidation');

                    // Use Ajax to submit form data
                    var url = globalUrl+"api/Expense";
                    $.ajax({
                        data:$form.serializeArray(),
                        type: "put",
                        url: url,
                        dataType: "json",
                        success: function (resp) {
                            if(resp.result)
                            {
                                //$("#events-result").text('Send data: ' + $form.serialize());
                                dataBindToTable($('#table'),$('#validForm'));
                                //关闭弹出窗口
                                $('#modal-DataEdit').modal('hide');
                            }
                            else
                            {
                                alert("用户名或密码错！");
                            }
                        },
                        error:function(){
                            alert("更新数据失败！");
                        }
                    });
                });

    });

    //编辑按钮数据传递
    $('#btn-CommonDataModify').on("click",function () {
        dataBindToModal($('#validForm'),$('#table'));
        SetSelectSelected($('#sign_type'),$('#sign_type').val());
        $('#modal-DataEdit').modal('show');
    });

    ///弹出层事件/////////////////////////////////////////////////////
    $('#modal-btn-save').on("click",function () {

        //$("#events-result").text('Selected values: ' + JSON.stringify($('#validForm').serializeArray()));
    });

</script>